# -------------------------------------------------------------------
#       -*- coding: utf-8 -*-
#   @Project    :   spider
#   @File       :   32_梨视频_防盗链.py
#   @Author     :   WANGYU
#   @Time       :   2021-08-19 11:15:27
#   @Software   :   PyCharm
#   @Desc       :   
# -------------------------------------------------------------------

import requests

# 拿到contId
# 拿到videoStatus返回到json 》srcURL
# srcURL里面内容进行修正
# 下载视频

url = 'https://www.pearvideo.com/video_1738894'
contId = url.split('_')[1]

videoStatusUrl = f'https://www.pearvideo.com/videoStatus.jsp?contId={contId}&mrd=0.8070810147079805'
headers = {
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36'
                      ' (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
        # 防盗链：溯源，当前本次请求到上一级
        'Referer': 'https://www.pearvideo.com/video_1738894'
    }
resp = requests.get(videoStatusUrl, headers=headers)
# print(resp.text)
# resp.json()['videoInfo']['videos']['srcUrl']
dic = resp.json()
srcUrl = dic['videoInfo']['videos']['srcUrl']
systemTime = dic['systemTime']
srcUrl = srcUrl.replace(systemTime,f'cont-{contId}')
print(srcUrl)